<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>事件移除</title>
</head>
<body>
<div id="test">测试内容</div>
<button style="width: 80px;height: 50px" id="btnAdd">添加</button>
<button style="width: 80px;height: 50px" id="btnDel">移除</button>
<script>
  function click(){
    console.log('clicked')
  }
  var test=document.getElementById('test')
  var btnAdd=document.getElementById('btnAdd');
  var btnDel=document.getElementById('btnDel');
  // 为btn添加事件处理函数
  btnAdd.onclick=function (){
      test.addEventListener("click",click);
  }
  //移除
  btnDel.onclick=function (){
    //移除事件监听方式
    test.removeEventListener("click",click);
  }
</script>
</body>
</html>